const {
    router,
    Result,
    querySql
} = require('../connect');
const boom = require('boom');
const { body, validationResult } = require('express-validator');
const {
    CODE_ERROR,
    CODE_SUCCESS
} = require('../utils/constant');

router.get('/roles', (req, res, next) => {
    const err = validationResult(req);
    // 如果验证出错，error不为空[]
    if (!err.isEmpty()) {
        // 获取错误信息
        const [{ msg }] = err.errors;
        // 抛出错误，交给我们自定义的统一异常处理程序进行错误返回 
        next(boom.badRequest(msg));
    } else {
        const sql = `select * from tb_role`

        querySql(sql).then(result => {
            res.json(new Result({
                code: CODE_SUCCESS,
                data: result
            }))
        })


    }
})

module.exports = router;